import easy_phot
import quickplotphot
import easy_phot_params as params
import os,glob
from pyraf import iraf
#IRAF photometry notes.
#run in ureka, by first running 'ur_setup' then 'python photometry.py'
#save a list of fits files to align:
#ls a*.fits > im.lis

#douglase@bu.edu. 10/28/2013


#run the photometry routine:
msg = 'Create a new list of stars for photometry or look for existing list? (will overwrite existing '+params.coofnamein+' if existant). (if y, make sure DS9 is running. Tested with SAOImage 6.1 in OS-X)'

newlist = True if raw_input("%s (yy/N) " % msg).lower() == 'yy' else False

if newlist:
    #delete old coordnate file and launch imexam to get alignment coordinates:
    
    files=glob.glob(params.image_dir+params.rootstr+'*'+params.alignstr+"")
    refname = files[0] #just using first image found as reference image

    try:
        os.remove(params.coofnamein)
    except Exception, err:
        print(err)
        
    try:
        iraf.set(stdimage= 'imt4096')
        print("use the letter a to select stars for alignment and photometry and q to quit\n Select star of INTEREST FIRST")
        iraf.imexam(refname,Stdout=params.coofnamein)#,Sterr='errs.txt')
    except Exception,e:
        print(e)
        
easy_phot.execute()
quickplotphot.plotphot()

        
